package com.ankiang.treeprint.model;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ankiang.treeprint.lib.Pinyin;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

public class TRRedpacketNode  implements Serializable {

    private int id;                       // id，用于索引
    private String userid;                // 用户id
    private int group;                    // 分组，区分不同分组
    private int amount;

    private boolean status;               // 完成状态
    private String title;                 // 姓名
    private String note;                  // 昵称
    private String inserttime;            // 插入时间
    private String updatetime;            // 更新时间
    private String viewtime;              // 查看时间



    public static TRRedpacketNode convert(JSONObject obj) {
        TRRedpacketNode item = new TRRedpacketNode();
        int id = obj.getIntValue("id");
        String userid = obj.getString("userid");
        boolean status = obj.getBoolean("status");
        String title = obj.getString("title");
        String note = obj.getString("note");

        String inserttime = obj.getString("inserttime");
        String updatetime = obj.getString("updatetime");
        String viewtime = obj.getString("viewtime");


        item.setId(id);
        item.setStatus(status);
        item.setTitle(title);
        item.setNote(note);

        item.setUpdatetime(updatetime);
        item.setViewtime(viewtime);
        item.setInserttime(inserttime);
        item.setUserid(userid);


        return item;
    }

    private void setViewtime(String viewtime) {
        this.viewtime = viewtime;
    }

    public String toJSONString(){
        String s = JSON.toJSONString(this, true);
        return s;
    }


    public void refreshViewtime() {
        String now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        this.viewtime = now;
    }

    public void refreshUpdatetime() {
        String now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        this.updatetime = now;
    }



    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUserid() {
        return this.userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    public int getGroup() {
        return this.group;
    }

    public void setGroup(int group) {
        this.group = group;
    }

    public boolean getStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }


    public String getInserttime() {
        return this.inserttime;
    }

    public void setInserttime(String inserttime) {
        this.inserttime = inserttime;
    }

    public String getViewtime() {
        return viewtime;
    }

    public String getUpdatetime() {
        return this.updatetime;
    }

    public void setUpdatetime(String updatetime) {
        this.updatetime = updatetime;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }
//    @Override
//    public TRRedpacketNode clone() {
//        TRRedpacketNode node;
////        node = TRRedpacketNode.convert(this);
//        return node;
//    }
}
